package com.example.demo.seven;

import com.example.demo.util.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

/**
 * 发送消息
 * 主题、主题交换机
 *
 * @author chensixiang chensixiang1234@gmail.com
 */
public class TopicLog {
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

        HashMap<String, String> map = new HashMap<>();
        map.put("quick.orange.rabbit", "Q1Q2");
        map.put("lazy.orange.elephant", "Q1Q2");
        map.put("quick.orange.fox", "Q1");
        map.put("lazy.pink.rabbit", "Q2");
        map.put("quick.bbb.fox", "null");
        map.put("quick.orange.male.rabbit", "null");
        map.put("lazy.orange.male.rabbit", "Q2");

        map.forEach((k, v) -> {
            try {
                channel.basicPublish(EXCHANGE_NAME, k, null, v.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        System.out.println("成功发送");
    }
}
